/**
 * Copyright (C), 2015-2018，XXX人名
 * FileName: TestController
 * Author:   Administrator
 * Date:     2018/4/3 14:18
 * Description: 控制类测试类
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.desheng.Controller;

import com.desheng.Service.TestService;
import com.desheng.bean.User;
import com.easyFramework.annotation.Autowired;
import com.easyFramework.annotation.Controller;
import com.easyFramework.annotation.RequestMapping;
import com.easyFramework.annotation.RequestParam;
import com.easyFramework.bean.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 〈一句话功能简述〉<br> 
 * 〈控制类测试类〉
 *
 * @author Administrator
 * @create 2018/4/3
 * @since 1.0.0
 */
//@Controller("test")
@Controller
@RequestMapping("/test")
public class TestController {

    @Autowired
    TestService testService;

    @RequestMapping(value = "/login",method = "post")
    public ModelAndView login(@RequestParam("username") Long userId,
                              @RequestParam("password") String password, HttpServletRequest request){
        HttpSession httpSession =request.getSession();
        ModelAndView modelAndView = new ModelAndView();
        System.out.println("userId====="+userId);
        User user =testService.find(userId,password);
        if(user==null){
            modelAndView.addModel("error","账号或密码错误");
            modelAndView.setPath("index.html");
        }else {
            httpSession.setAttribute("user", user);
            System.out.println("登录成功");
            modelAndView.setPath("home.jsp");
        }
        return modelAndView;
    }

//    @RequestMapping("/add")
//    public ModelAndView regist(User user){
//        ModelAndView modelAndView = new ModelAndView();
//        System.out.println("注册name====="+user.getUsername());
//        User a = new User();
//        testService.add(a);
//        System.out.println("a.getUsername()"+a.getUsername());
//        modelAndView.setPath("main.jsp");
//
//        return modelAndView;
//    }
//
//    @RequestMapping("/regist")
//    public ModelAndView regist(){
//        ModelAndView modelAndView = new ModelAndView();
//        modelAndView.setPath("regist.jsp");
//        return modelAndView;
//    }



}
